<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="s_tech_process" :rules="rules" label-width="100px" id="mvcfm">
          <div class="form-unit">
            <span class="mvc-title-left"> 配置材料 </span>
          </div>
          <el-table :data="s_tech_process">
            <el-table-column label="工序名称" prop="process_name">
            </el-table-column>
            <el-table-column label="工序编号" prop="process_num">
            </el-table-column>
            <el-table-column label="适用材料" prop="product_id">
              <template slot-scope="scope">
                {{scope.row.product_id}}
                <el-button @click="popSetMaterialProcedure('product_id','product_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
              </template>
            </el-table-column>
            <el-table-column label="最小生产数" prop="stuff_min_produce">
              <template slot-scope="scope">
                <div class="el-select">
                  <el-input type="text" v-model="scope.row.stuff_min_produce" />
                </div>
                <el-button @click="popSetMaterialMini('stuff_min_produce','stuff_min_produce')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-button @click="setMaterialSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'适用产品'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="SetMaterialProcedureVisible" append-to-body>
      <SetMaterialProcedure v-if="SetMaterialProcedureVisible" ref="SetMaterialProcedure" :popparams="popparams"> </SetMaterialProcedure>
    </el-dialog>
    <el-dialog :visible.sync="SetMaterialMiniVisible" append-to-body>
      <SetMaterialMini v-if="SetMaterialMiniVisible" ref="SetMaterialMini" :popparams="popparams"> </SetMaterialMini>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SetMaterialProcedure from "@/views/mes/product/SetMaterialProcedure";
  import SetMaterialMini from "@/views/mes/product/SetMaterialMini";
  export default {
    name: 'SetMaterial',
    components: {
      SetMaterialProcedure,
      SetMaterialMini,
    },
    props: ['popparams'],
    data() {
      return {
        SetMaterialProcedureVisible: false,
        SetMaterialProcedureValue: null,
        SetMaterialProcedureDesc: null,
        SetMaterialMiniVisible: false,
        SetMaterialMiniValue: null,
        SetMaterialMiniDesc: null,
        vueparams: this.getVUEParams(""),
        s_tech_process: [],
        loading: false,
        Container: null,
        rules: {}
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "28847805EE1D403DBCD43478FD18BD08",
        name: "工艺右菜单",
        selected: "适用产品"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/product/TechnologyAction/setMaterial?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      setMaterialSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/product/TechnologyAction/setMaterialSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/mes/product/SetMaterialDet/setMaterialDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popSetMaterialProcedure(desc, value) {
        this.SetMaterialProcedureVisible = true;
        this.SetMaterialProcedureDesc = desc;
        this.SetMaterialProcedureValue = value;
      },
      closeSetMaterialProcedure(value, desc) {
        this.SetMaterialProcedureVisible = false;
        this.$set(this.s_tech_process, this.SetMaterialProcedureDesc, desc);
        this.$set(this.s_tech_process, this.SetMaterialProcedureValue, value);
      },
      popSetMaterialMini(desc, value) {
        this.SetMaterialMiniVisible = true;
        this.SetMaterialMiniDesc = desc;
        this.SetMaterialMiniValue = value;
      },
      closeSetMaterialMini(value, desc) {
        this.SetMaterialMiniVisible = false;
        this.$set(this.s_tech_process, this.SetMaterialMiniDesc, desc);
        this.$set(this.s_tech_process, this.SetMaterialMiniValue, value);
      },
    },
  }
</script>
